<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<style>
<!--
input {
	line-height: 27px;
}
.h10{
	height: 10px;
}
.btn {
    line-height: 23px;
}
.lefttable {
 width: 85%;
 float: left;
 padding-right: 10px;
}
.righttable {
 width: 15%;
 float: right;
}

#grouptable td {
	text-align: center;
	vertical-align: middle;
}

.hand {
	cursor: hand;
}
.tablerow:hover{
	background-color: #eeeeff;
}
-->
</style>
<script type="text/javascript">
var group = [];
<c:forEach items="${group }" var="record">
group.push({'id':'${record.id}','name':'${record.name}'});
</c:forEach>

function editGroupFun(cbox) {
	pageii = layer.open({
		title : "编辑分组",
		type : 2,
		area : [ "600px", "195px" ],
		content : [rootPath + '/group/editUI.shtml?id=' + cbox, 'no'],
		end : function() {
			reloadGroup();
		}
	});
	return false;
}
function addGroupFun() {
	pageii = layer.open({
		title : "添加分组",
		type : 2,
		area : [ "600px", "195px" ],
		content : [rootPath + '/group/addUI.shtml', 'no'],
		end : function() {
			reloadGroup();
		}
	});
}
function doSearch(groupId) {
	$(".tablerow").css("background-color", "");
	$("#rowid" + groupId).css("background-color", "#e3e3e3");
	$("input[name='weixinUserFormMap.groupId']").val(groupId);
	$("#search").click();
}

function reloadGroup() {
	$(".edit").remove();
	var data = CommnUtil.ajax("${pageContext.request.contextPath}/group/listAll.shtml", {}, "json");
	group = [];
	$.each(data, function(i,e) {
		group.push({'id': e.id,'name': e.name});
		if (e.id == 1) return true;
		$("#grouptable tbody").append("<tr class='tablerow edit' id='rowid" + e.id + "'>" +
			"<td><img class='imgbtn' title='编辑分组' src='${pageContext.request.contextPath}/images/edit.png' onclick=editGroupFun('" + e.id + "')></td>" +
			"<td class='hand' onclick=doSearch('" + e.id + "')>" + e.name + "</td></tr>");
	});
	$("#search").click();
}
</script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/func/listWeixinUser.js"></script>
	<div class="lefttable">
		<div class="m-b-md">
			<div class="h10"></div>
			<form class="form-inline" role="form" id="searchForm" name="searchForm">
				<input type="hidden" name="weixinUserFormMap.groupId" value="">
				<div class="form-group">
					<label class="control-label">
					<span>昵称:</span></label>
					<input class="input-medium ui-autocomplete-input" qt="like" id="name" name="weixinUserFormMap.name">
				</div>
				<div class="form-group">
					<label class="control-label">
					<span>医院名称:</span></label>
					<input class="input-medium ui-autocomplete-input" qt="like" id="hospitalName" name="weixinUserFormMap.hospitalName">
				</div>
				<div class="form-group">
					<label class="control-label">
					<span>医生姓名:</span></label>
					<input class="input-medium ui-autocomplete-input" qt="like" id="doctorName" name="weixinUserFormMap.doctorName">
				</div>
				<a href="javascript:void(0)" class="btn btn-default" id="search">查询</a>
			</form>
		</div>
		<header class="panel-heading">
		<div class="doc-buttons">
			<c:forEach items="${res}" var="key">
				${key.description}
			</c:forEach>
		</div>
		</header>
		<div class="table-responsive">
			<div id="paging" class="pagclass"></div>
		</div>
	</div>
	<div class="righttable pagclass">
		<div class="table-responsive">
			<table id="grouptable" class="pp-list table" style="table-layout: fixed;margin-top: 10px;width:100%">
			   <thead>
			    <tr>
			     <th style="text-align:center;width: 55px;">
			     	<img class="imgbtn" title="添加分组" src="${pageContext.request.contextPath}/images/add.png" onclick="addGroupFun();" />
			     </th>
			     <th style="text-align:center;width: auto;">组名</th>
			    </tr>
			   </thead>
			   <tbody>
			    <tr class="tablerow" id="rowid">
			     <td>&nbsp;</td>
			     <td class="hand" onclick="doSearch('')">全部</td>
			    </tr>
			    <c:forEach var="record" items="${group }" varStatus="s">
		     	<c:choose>
		     		<c:when test="${s.index == 0 }">
	     			<tr class="tablerow" id="rowid${record.id }">
	     				<td style="width: 55px">&nbsp;</td>
	     				<td class="hand" onclick="doSearch('${record.id}')">${record.name}</td>
	     			</tr>
	     			</c:when>
		     		<c:otherwise>
		     			<tr class="tablerow edit" id="rowid${record.id }">
	     					<td><img class="imgbtn" title="编辑分组" src="${pageContext.request.contextPath}/images/edit.png" onclick="editGroupFun('${record.id}');" /></td>
		     				<td class="hand" onclick="doSearch('${record.id}')">${record.name}</td>
		     			</tr>
		     		</c:otherwise>
		     	</c:choose>
			    </c:forEach>
			   </tbody>
			</table>
		</div>
	</div>